/*     */ package com.zimbra.qa.unittest.prov.soap;
/*     */ 
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.soap.Element.XMLElement;
/*     */ import com.zimbra.common.soap.SoapFaultException;
/*     */ import com.zimbra.common.soap.SoapProtocol;
/*     */ import com.zimbra.common.soap.SoapTransport;
/*     */ import com.zimbra.common.soap.ZimbraNamespace;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.soap.JaxbUtil;
/*     */ import com.zimbra.soap.account.message.CreateSignatureRequest;
/*     */ import com.zimbra.soap.account.type.Signature;
/*     */ import org.junit.AfterClass;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestBatchRequest
/*     */   extends SoapTest
/*     */ {
/*     */   private static SoapProvTestUtil provUtil;
/*     */   private static Provisioning prov;
/*     */   private static Domain domain;
/*     */   
/*     */   @BeforeClass
/*     */   public static void init()
/*     */     throws Exception
/*     */   {
/*  51 */     provUtil = new SoapProvTestUtil();
/*  52 */     prov = provUtil.getProv();
/*  53 */     domain = provUtil.createDomain(baseDomainName());
/*     */   }
/*     */   
/*     */   @AfterClass
/*     */   public static void cleanup() throws Exception {
/*  58 */     Cleanup.deleteAll(new String[] { baseDomainName() });
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void batchReqWithoutCsrfToken() throws Exception {
/*  63 */     Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
/*  64 */     boolean csrfEnabled = Boolean.TRUE.booleanValue();
/*  65 */     SoapTransport transport = authUser(acct.getName(), csrfEnabled, Boolean.FALSE.booleanValue());
/*     */     
/*  67 */     Element request = new Element.XMLElement(ZimbraNamespace.E_BATCH_REQUEST);
/*  68 */     String sigContent = "xss&lt;script&gt;alert(\"XSS\")&lt;/script&gt;&lt;a href=javascript:alert(\"XSS\")&gt;&lt;";
/*     */     
/*  70 */     Signature sig = new Signature("test_id", "testSig", sigContent, "text/html");
/*  71 */     CreateSignatureRequest req = new CreateSignatureRequest(sig);
/*  72 */     SoapProtocol proto = SoapProtocol.Soap12;
/*  73 */     Element sigReq = JaxbUtil.jaxbToElement(req, proto.getFactory());
/*  74 */     request.addElement(sigReq);
/*     */     try {
/*  76 */       transport.invoke(request, false, false, null);
/*     */     } catch (SoapFaultException e) {
/*  78 */       org.junit.Assert.assertNotNull(e);
/*  79 */       junit.framework.Assert.assertEquals(true, e.getCode().contains("AUTH_REQUIRED"));
/*     */     }
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void batchReqWithCsrfToken() throws Exception {
/*  85 */     Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
/*  86 */     boolean csrfEnabled = Boolean.TRUE.booleanValue();
/*  87 */     SoapTransport transport = authUser(acct.getName(), csrfEnabled, Boolean.TRUE.booleanValue());
/*     */     
/*  89 */     Element request = new Element.XMLElement(ZimbraNamespace.E_BATCH_REQUEST);
/*  90 */     String sigContent = "xss&lt;script&gt;alert(\"XSS\")&lt;/script&gt;&lt;a href=javascript:alert(\"XSS\")&gt;&lt;";
/*     */     
/*  92 */     Signature sig = new Signature(null, "testSig", sigContent, "text/html");
/*  93 */     CreateSignatureRequest req = new CreateSignatureRequest(sig);
/*  94 */     SoapProtocol proto = SoapProtocol.Soap12;
/*  95 */     Element sigReq = JaxbUtil.jaxbToElement(req, proto.getFactory());
/*  96 */     request.addElement(sigReq);
/*     */     try {
/*  98 */       Element sigResp = transport.invoke(request, false, false, null);
/*  99 */       String sigt = sigResp.getElement("CreateSignatureResponse").getElement("signature").getAttribute("id");
/* 100 */       org.junit.Assert.assertNotNull(sigt);
/*     */     } catch (SoapFaultException e) {
/* 102 */       org.junit.Assert.assertNull(e);
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/soap/TestBatchRequest.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */